/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * JP_GenerarOrdenTrabajo.java
 *
 * Created on Jul 13, 2009, 11:21:50 AM
 */

package gui;
import controlacciones.ejb3.entity.TbAccion;
import delegate.GestionDelegate;
import controlacciones.ejb3.entity.TbArea;
import controlacciones.ejb3.pojo.TableBeanBinding_Accion;
import controlacciones.ejb3.pojo.TableBeanBinding_DatosAcciones;
import helper.JP_Modelo;
import helper.JP_Utiles_PanelModelo;
import helper.Utiles_Fecha_Cliente;
import helper.Utiles_MensajesDialogo;
import java.io.File;
import java.sql.SQLException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.text.MaskFormatter;
import net.sf.jasperreports.engine.JRException;
import org.jdesktop.application.Action;
import org.jdesktop.application.Task;
/**
 *
 * @author Vanessa
 */
public class JP_AnularAccion extends JP_Utiles_PanelModelo {

    /** Creates new form JP_GenerarOrdenTrabajo */
    public JP_AnularAccion() {
        inicializaComponentes();        
    }

    private void inicializaComponentes(){
        initComponents();
        this.cargaComboArea();        
    }

    private void cargaComboArea(){
        List listTbArea = null; // seteamos variable local
        List listaArea = comboBeanBindingArea1.getLista();
        listaArea.clear();
        try {
            listTbArea = GestionDelegate.getInstance().getListaArea();
        } catch (Exception e) {
            System.out.println( "Error en gestionDelegate.getListaArea()" );
            return;
        }
        this.comboBeanBindingArea1.setLista(listTbArea);
        this.bindingGroup.bind();
        this.cmbArea.updateUI();
        if( listTbArea.size() > 0 ){
            this.cmbArea.setSelectedIndex( 0 );
        }
    }
    
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {
        bindingGroup = new org.jdesktop.beansbinding.BindingGroup();

        comboBeanBindingArea1 = new beansbinding.ComboBeanBindingArea();
        jp_DocumentoIdentificacion = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        cmbArea = new javax.swing.JComboBox();
        jLabel3 = new javax.swing.JLabel();
        try{
            mascara = new javax.swing.text.MaskFormatter("##/##/####");
        }catch(Exception e){
            System.out.println("Error en mascara");
        }

        ftxtFecRegistro = new javax.swing.JFormattedTextField();
        ftxtFecRegistro = new javax.swing.JFormattedTextField(mascara);

        btnConsultar = new javax.swing.JButton();
        jLabel5 = new javax.swing.JLabel();
        jtxtNumeroInscrip = new javax.swing.JTextField();
        jLabel2 = new javax.swing.JLabel();
        jtxtTipoAccion = new javax.swing.JTextField();
        jp_Acciones = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        tbAcciones = new javax.swing.JTable();
        jPanel1 = new javax.swing.JPanel();
        btnPrimero = new javax.swing.JButton();
        btnAnterior = new javax.swing.JButton();
        btnSiguiente = new javax.swing.JButton();
        btnUltimo = new javax.swing.JButton();
        btnCerrar = new javax.swing.JButton();
        jlblPagina = new javax.swing.JLabel();
        btnGuardar = new javax.swing.JButton();

        jp_DocumentoIdentificacion.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Buscar Acción", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Arial 12", 1, 12))); // NOI18N

        jLabel1.setFont(new java.awt.Font("Arial 12", 1, 12));
        jLabel1.setText("Area:");

        org.jdesktop.beansbinding.ELProperty eLProperty = org.jdesktop.beansbinding.ELProperty.create("${lista}");
        org.jdesktop.swingbinding.JComboBoxBinding jComboBoxBinding = org.jdesktop.swingbinding.SwingBindings.createJComboBoxBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, comboBeanBindingArea1, eLProperty, cmbArea);
        bindingGroup.addBinding(jComboBoxBinding);

        cmbArea.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cmbAreaActionPerformed(evt);
            }
        });
        cmbArea.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                cmbAreaKeyPressed(evt);
            }
        });

        jLabel3.setFont(new java.awt.Font("Arial 12 12", 1, 12));
        jLabel3.setText("Fecha de Registro:");

        ftxtFecRegistro.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                ftxtFecRegistroActionPerformed(evt);
            }
        });
        ftxtFecRegistro.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                ftxtFecRegistroKeyPressed(evt);
            }
        });

        btnConsultar.setFont(new java.awt.Font("Arial", 1, 12));
        btnConsultar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/org/fife/plaf/Office2003/find.gif"))); // NOI18N
        btnConsultar.setText("Consultar");
        btnConsultar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnConsultarActionPerformed(evt);
            }
        });

        jLabel5.setFont(new java.awt.Font("Arial 12 12", 1, 12));
        jLabel5.setText("Numero de Inscripción");

        jtxtNumeroInscrip.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jtxtNumeroInscripActionPerformed(evt);
            }
        });

        jLabel2.setFont(new java.awt.Font("Arial 12", 1, 12));
        jLabel2.setText("CodTipo Acción:");

        jtxtTipoAccion.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                jtxtTipoAccionKeyPressed(evt);
            }
        });

        javax.swing.GroupLayout jp_DocumentoIdentificacionLayout = new javax.swing.GroupLayout(jp_DocumentoIdentificacion);
        jp_DocumentoIdentificacion.setLayout(jp_DocumentoIdentificacionLayout);
        jp_DocumentoIdentificacionLayout.setHorizontalGroup(
            jp_DocumentoIdentificacionLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jp_DocumentoIdentificacionLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jp_DocumentoIdentificacionLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel2)
                    .addComponent(jLabel1))
                .addGap(18, 18, 18)
                .addGroup(jp_DocumentoIdentificacionLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(jtxtTipoAccion)
                    .addComponent(cmbArea, javax.swing.GroupLayout.PREFERRED_SIZE, 157, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(49, 49, 49)
                .addGroup(jp_DocumentoIdentificacionLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel3)
                    .addComponent(jLabel5))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jp_DocumentoIdentificacionLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jtxtNumeroInscrip, javax.swing.GroupLayout.PREFERRED_SIZE, 147, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(ftxtFecRegistro, javax.swing.GroupLayout.DEFAULT_SIZE, 147, Short.MAX_VALUE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(btnConsultar, javax.swing.GroupLayout.PREFERRED_SIZE, 119, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(40, 40, 40))
        );
        jp_DocumentoIdentificacionLayout.setVerticalGroup(
            jp_DocumentoIdentificacionLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jp_DocumentoIdentificacionLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jp_DocumentoIdentificacionLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jp_DocumentoIdentificacionLayout.createSequentialGroup()
                        .addComponent(cmbArea, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jtxtTipoAccion, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jp_DocumentoIdentificacionLayout.createSequentialGroup()
                        .addComponent(jLabel1)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLabel2))
                    .addGroup(jp_DocumentoIdentificacionLayout.createSequentialGroup()
                        .addGroup(jp_DocumentoIdentificacionLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(ftxtFecRegistro, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel3))
                        .addGap(5, 5, 5)
                        .addGroup(jp_DocumentoIdentificacionLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel5)
                            .addComponent(jtxtNumeroInscrip, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(btnConsultar))))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jp_Acciones.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Detalle de acciones", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Arial 12 12 12 12", 1, 12))); // NOI18N

        tbAcciones.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {},
                {},
                {},
                {}
            },
            new String [] {

            }
        ));
        jScrollPane1.setViewportView(tbAcciones);

        javax.swing.GroupLayout jp_AccionesLayout = new javax.swing.GroupLayout(jp_Acciones);
        jp_Acciones.setLayout(jp_AccionesLayout);
        jp_AccionesLayout.setHorizontalGroup(
            jp_AccionesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jp_AccionesLayout.createSequentialGroup()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 759, Short.MAX_VALUE)
                .addContainerGap())
        );
        jp_AccionesLayout.setVerticalGroup(
            jp_AccionesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 335, Short.MAX_VALUE)
        );

        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder(""));

        btnPrimero.setIcon(new javax.swing.ImageIcon(getClass().getResource("/gui/resources/images/2leftarrow.gif"))); // NOI18N
        btnPrimero.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnPrimeroActionPerformed(evt);
            }
        });

        btnAnterior.setIcon(new javax.swing.ImageIcon(getClass().getResource("/gui/resources/images/1leftarrow.gif"))); // NOI18N
        btnAnterior.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnAnteriorActionPerformed(evt);
            }
        });

        btnSiguiente.setIcon(new javax.swing.ImageIcon(getClass().getResource("/gui/resources/images/1rightarrow.gif"))); // NOI18N
        btnSiguiente.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnSiguienteActionPerformed(evt);
            }
        });

        btnUltimo.setIcon(new javax.swing.ImageIcon(getClass().getResource("/gui/resources/images/2rightarrow.gif"))); // NOI18N
        btnUltimo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnUltimoActionPerformed(evt);
            }
        });

        btnCerrar.setFont(new java.awt.Font("Arial", 1, 12));
        btnCerrar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/org/fife/plaf/Office2003/close.gif"))); // NOI18N
        btnCerrar.setText("Cerrar");
        btnCerrar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnCerrarActionPerformed(evt);
            }
        });

        jlblPagina.setForeground(new java.awt.Color(0, 102, 204));

        javax.swing.ActionMap actionMap = org.jdesktop.application.Application.getInstance(controlaccionescomercial.ControlAccionesComercialApp.class).getContext().getActionMap(JP_AnularAccion.class, this);
        btnGuardar.setAction(actionMap.get("procesaAnulacion")); // NOI18N
        btnGuardar.setFont(new java.awt.Font("Arial", 1, 12)); // NOI18N
        btnGuardar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/org/fife/plaf/Office2003/save.gif"))); // NOI18N
        btnGuardar.setText("Guardar");
        btnGuardar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnGuardarActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jlblPagina, javax.swing.GroupLayout.DEFAULT_SIZE, 238, Short.MAX_VALUE)
                .addGap(18, 18, 18)
                .addComponent(btnPrimero, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(btnAnterior, javax.swing.GroupLayout.PREFERRED_SIZE, 49, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(btnSiguiente, javax.swing.GroupLayout.PREFERRED_SIZE, 55, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(btnUltimo, javax.swing.GroupLayout.PREFERRED_SIZE, 60, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(44, 44, 44)
                .addComponent(btnGuardar, javax.swing.GroupLayout.PREFERRED_SIZE, 109, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(btnCerrar, javax.swing.GroupLayout.PREFERRED_SIZE, 97, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(btnUltimo, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(btnSiguiente, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(btnAnterior, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(btnPrimero, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jlblPagina, javax.swing.GroupLayout.DEFAULT_SIZE, 25, Short.MAX_VALUE)
                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(btnCerrar, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(btnGuardar, javax.swing.GroupLayout.DEFAULT_SIZE, 25, Short.MAX_VALUE)))
                .addContainerGap())
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jp_Acciones, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addComponent(jp_DocumentoIdentificacion, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jp_DocumentoIdentificacion, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(1, 1, 1)
                .addComponent(jp_Acciones, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, 37, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );

        bindingGroup.bind();
    }// </editor-fold>//GEN-END:initComponents

    private void cargaTabla(){
        TbArea area;
        String fecha, codTipoAccion, numInscri;
        try {
            area = (TbArea) this.cmbArea.getSelectedItem();
        } catch (Exception e) {
            Utiles_MensajesDialogo.mensajeAlerta("Seleccione el area");
            return;
        }

        fecha = this.ftxtFecRegistro.getText().trim();

        Utiles_Fecha_Cliente fecIni = new Utiles_Fecha_Cliente(fecha);
        if( !fecIni.isValida() ){
            Utiles_MensajesDialogo.mensajeAlerta("Ingrese una fecha de inicio valida");
            return;
        }
        codTipoAccion = this.jtxtTipoAccion.getText().trim();
        numInscri = this.jtxtNumeroInscrip.getText().trim();
        
        try {

            listaDatos = GestionDelegate.getInstance().getListaDatosAcciones(area, fecha, codTipoAccion, numInscri, pagActual, pagTamanno);
        } catch (Exception ex) {
            //Logger.getLogger(JP_ListarAcciones_Area.class.getName()).log(Level.SEVERE, null, ex);
            System.out.println( "Error al listar acciones: " + ex.getMessage() );
        }
        construirTabla();
        if( listaDatos.size() > 0  ){
            //this.btnProcesar.requestFocus();
        }else{
            this.ftxtFecRegistro.requestFocus();
        }
    }

    public void construirTabla(){

        this.jlblPagina.setText("Página actual: " + pagActual);

        bindingGroup = new org.jdesktop.beansbinding.BindingGroup();
        jTableBinding = org.jdesktop.swingbinding.SwingBindings.createJTableBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, listaDatos, tbAcciones);
        org.jdesktop.swingbinding.JTableBinding.ColumnBinding columnBinding0 = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${idAccion}"));
        columnBinding0.setColumnName("Id. Accion ");
        columnBinding0.setColumnClass(String.class);
        columnBinding0.setEditable(false);

        org.jdesktop.swingbinding.JTableBinding.ColumnBinding columnBinding1 = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${numInscrip}"));
        columnBinding1.setColumnName("Numero de inscripcion");
        columnBinding1.setColumnClass(String.class);
        columnBinding1.setEditable(false);

        org.jdesktop.swingbinding.JTableBinding.ColumnBinding columnBinding2 = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${nombre}"));
        columnBinding2.setColumnName("Nombre");
        columnBinding2.setColumnClass(String.class);
        columnBinding2.setEditable(false);

        org.jdesktop.swingbinding.JTableBinding.ColumnBinding columnBinding3 = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${direccion}"));
        columnBinding3.setColumnName("Direccion");
        columnBinding3.setColumnClass(String.class);
        columnBinding3.setEditable(false);

        org.jdesktop.swingbinding.JTableBinding.ColumnBinding columnBinding4 = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${cod_tipo_accion}"));
        columnBinding4.setColumnName("Cod Tipo Accion");
        columnBinding4.setColumnClass(String.class);
        columnBinding4.setEditable(false);

        org.jdesktop.swingbinding.JTableBinding.ColumnBinding columnBinding5 = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${descripcionAccion}"));
        columnBinding5.setColumnName("Descripcion Accion");
        columnBinding5.setColumnClass(String.class);
        columnBinding5.setEditable(false);

        org.jdesktop.swingbinding.JTableBinding.ColumnBinding columnBinding6 = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${fechaRegistro}"));
        columnBinding6.setColumnName("Fecha Registro");
        columnBinding6.setColumnClass(String.class);
        columnBinding6.setEditable(false);

        org.jdesktop.swingbinding.JTableBinding.ColumnBinding columnBinding7 = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${flagAnulada}"));
        columnBinding7.setColumnName("Anulada");
        columnBinding7.setColumnClass(Boolean.class);
        columnBinding7.setEditable(true);

        org.jdesktop.swingbinding.JTableBinding.ColumnBinding columnBinding8 = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${flagAprobada}"));
        columnBinding8.setColumnName("Aprobada");
        columnBinding8.setColumnClass(Boolean.class);
        columnBinding8.setEditable(false);

        bindingGroup.addBinding(jTableBinding);
        bindingGroup.bind();
    }

    public boolean generarArchivo( List<TableBeanBinding_DatosAcciones>  listaDatos ,File file){
        return helper.Utiles_ExportarExcel.escribirExcelLista(listaDatos, file);
    }
  
    private void procesarCambios(  ) throws Exception{
         TbAccion tbAccion = null;
        //int[] selected = this.tabla.getSelectedRows();
        //List< TableBeanBinding_DatosAccionesAprobar> toRemove = new ArrayList<TableBeanBinding_DatosClasificacionTipoAccionArea>(selected.length);
        for (int idx = 0; idx < this.tbAcciones.getRowCount(); idx++) {
            TableBeanBinding_Accion t = this.listaDatos.get(tbAcciones.convertRowIndexToModel(idx));
            tbAccion = GestionDelegate.getInstance().buscarAccion( t.getIdAccion() );
            tbAccion.setFlagAnulada( t.getFlagAnulada() );
            System.out.println("setFlagAnulada: " +  t.getFlagAnulada() );
            GestionDelegate.getInstance().actualizarAccion(tbAccion);
        }
    }

    @Action
    public Task procesaAnulacion() {
        return new Procesa(org.jdesktop.application.Application.getInstance(controlaccionescomercial.ControlAccionesComercialApp.class));
    }

    private class Procesa extends org.jdesktop.application.Task<Object, Void> {
        Procesa(org.jdesktop.application.Application app) {
            super(app);
        }
        @Override protected Object doInBackground() {
            btnConsultar.setEnabled(false);
            btnGuardar.setEnabled(false);
            btnCerrar.setEnabled(false);
            try {
                procesarCambios();
                helper.Utiles_MensajesDialogo.mensajeExito();
            } catch (Exception ex) {
                helper.Utiles_MensajesDialogo.mensajeError("Error: " + ex.getMessage());
                System.out.println("Procesa anulacion: " + ex.getMessage());
            }
            btnConsultar.setEnabled(true);
            btnGuardar.setEnabled(true);
            btnCerrar.setEnabled(true);
            return null;  // return your result
        }
        @Override protected void succeeded(Object result) {
        }
    }
       
    private void btnConsultarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnConsultarActionPerformed
        this.getNumPaginas();
        this.cargaTabla();
    }//GEN-LAST:event_btnConsultarActionPerformed

    private void btnCerrarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCerrarActionPerformed
        this.cerrarPadre();
    }//GEN-LAST:event_btnCerrarActionPerformed

    private void cmbAreaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cmbAreaActionPerformed
       
    }//GEN-LAST:event_cmbAreaActionPerformed

    private void ftxtFecRegistroActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ftxtFecRegistroActionPerformed
        this.jtxtNumeroInscrip.requestFocus();
    }//GEN-LAST:event_ftxtFecRegistroActionPerformed

    private void cmbAreaKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_cmbAreaKeyPressed
        if( evt.getKeyCode() == evt.VK_ENTER ){
            this.jtxtTipoAccion.requestFocus();
        }
    }//GEN-LAST:event_cmbAreaKeyPressed

    private void btnPrimeroActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnPrimeroActionPerformed
        this.primero();
        this.cargaTabla();
}//GEN-LAST:event_btnPrimeroActionPerformed

    private void btnAnteriorActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnAnteriorActionPerformed
        this.anterior();
        this.cargaTabla();
}//GEN-LAST:event_btnAnteriorActionPerformed

    private void btnSiguienteActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnSiguienteActionPerformed
        this.siguiente();
        this.cargaTabla();
}//GEN-LAST:event_btnSiguienteActionPerformed

    private void btnUltimoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnUltimoActionPerformed
        this.ultimo();
        this.cargaTabla();
}//GEN-LAST:event_btnUltimoActionPerformed

    private void jtxtTipoAccionKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jtxtTipoAccionKeyPressed
        if( evt.getKeyCode() == evt.VK_ENTER ){
            this.ftxtFecRegistro.requestFocus();
        }
    }//GEN-LAST:event_jtxtTipoAccionKeyPressed

    private void ftxtFecRegistroKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_ftxtFecRegistroKeyPressed
        // TODO add your handling code here:
    }//GEN-LAST:event_ftxtFecRegistroKeyPressed

    private void jtxtNumeroInscripActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jtxtNumeroInscripActionPerformed
        this.btnConsultar.requestFocus();
    }//GEN-LAST:event_jtxtNumeroInscripActionPerformed

    private void btnGuardarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnGuardarActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_btnGuardarActionPerformed

    public void generarReporteLecturas(){
        Map parametros = new HashMap();

        TbArea area = null;
        String fechaIni = null;
        String fechaFin = null;

        try {
            area = (TbArea) this.cmbArea.getSelectedItem();
        } catch (Exception e) {
            Utiles_MensajesDialogo.mensajeAlerta("Seleccione el area");
            return;
        }

        fechaIni = this.ftxtFecRegistro.getText().trim();
        Utiles_Fecha_Cliente fecIni = new Utiles_Fecha_Cliente(fechaIni);
        if( !fecIni.isValida() ){
            Utiles_MensajesDialogo.mensajeAlerta("Ingrese una fecha valida");
            return;
        }
        fechaFin = fechaIni;

        parametros.put("COD_AREA", area.getCodArea() );
        parametros.put("FECHA_INICIO" , fechaIni);
        parametros.put("FECHA_FIN", fechaFin );

        System.err.println("COD_AREA  " + area.getCodArea() );
        System.err.println("FECHA_INICIO  " + fechaIni);
        System.err.println("FECHA_FIN  "+ fechaFin );
        try {
            helper.Utiles_Reporte.generarReporte("Reporte_Acciones_Area_intervaloFechas_OrdenadoFechas.jasper", parametros);
        } catch (JRException ex) {
            //Logger.getLogger(JP_ListarAcciones_Area.class.getName()).log(Level.SEVERE, null, ex);
            System.err.println( "Error al generar el reporte1: " + ex.getMessage() );
        } catch (Exception ex) {
            //Logger.getLogger(JP_ListarAcciones_Area.class.getName()).log(Level.SEVERE, null, ex);
            System.err.println( "Error al generar el reporte2: " + ex.getMessage() );
        }
    }

    @Action
    public Task generarReporte() {
        return new GenerarReporte(org.jdesktop.application.Application.getInstance(controlaccionescomercial.ControlAccionesComercialApp.class));
    }

    private class GenerarReporte extends org.jdesktop.application.Task<Object, Void> {
        GenerarReporte(org.jdesktop.application.Application app) {
            super(app);
        }
        @Override protected Object doInBackground() {
            btnConsultar.setEnabled(false);
            btnGuardar.setEnabled(false);
            btnCerrar.setEnabled(false);
//            btnReporte.setEnabled(false);
            generarReporteLecturas();
            btnConsultar.setEnabled(true);
            btnGuardar.setEnabled(true);
            btnCerrar.setEnabled(true);
//            btnReporte.setEnabled(true);
            return null;  // return your result
        }
        @Override protected void succeeded(Object result) {
        }
    }

    public void primero(){
        pagActual = 0;
        System.out.println("pagActual: " + pagActual);
        
    }

    public void siguiente() {
        if( pagActual < this.pagUltima){
            pagActual++;            
        }
        this.jlblPagina.setText("Página actual: " + pagActual);
        
    }

    public void anterior() {
        pagActual--;
        if (pagActual < 0) {
            pagActual = 0;
        }        
        System.out.println("pagActual: " + pagActual);
    }

    public void ultimo(){        
        pagActual = pagUltima;
        
    }

    public void getNumPaginas(){
        try {
            int num_registros = getNumRegistros();
            if (pagTamanno > 0) {
                double ultima = num_registros / pagTamanno;
                System.out.println("ultima:" + ultima);
                pagUltima = (int) java.lang.Math.ceil(ultima);
                System.out.println("pagUltima: " + pagUltima);
            }
        } catch (Exception e) {
        }
        System.out.println("pagUltima: " + pagUltima);
    }

    public int getNumRegistros(){
        int num = 40;
        TbArea area;
        String fechaIni;
        try {
            area = (TbArea) this.cmbArea.getSelectedItem();
        } catch (Exception e) {            
            return 1;
        }

        fechaIni = this.ftxtFecRegistro.getText().trim();

        Utiles_Fecha_Cliente fecIni = new Utiles_Fecha_Cliente(fechaIni);
        if( !fecIni.isValida() ){
            Utiles_MensajesDialogo.mensajeAlerta("Ingrese una fecha de inicio valida");
            return 1;
        }
        
        try {
            num = GestionDelegate.getInstance().getNumRegistrosAcciones(area, fechaIni);
            System.out.println( "Num de Registros: " + num );
        } catch (Exception e) {
            System.out.println(e.getMessage());
        }
        return num;
    }
   



    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnAnterior;
    private javax.swing.JButton btnCerrar;
    private javax.swing.JButton btnConsultar;
    private javax.swing.JButton btnGuardar;
    private javax.swing.JButton btnPrimero;
    private javax.swing.JButton btnSiguiente;
    private javax.swing.JButton btnUltimo;
    private javax.swing.JComboBox cmbArea;
    private beansbinding.ComboBeanBindingArea comboBeanBindingArea1;
    private javax.swing.JFormattedTextField ftxtFecRegistro;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JLabel jlblPagina;
    private javax.swing.JPanel jp_Acciones;
    private javax.swing.JPanel jp_DocumentoIdentificacion;
    private javax.swing.JTextField jtxtNumeroInscrip;
    private javax.swing.JTextField jtxtTipoAccion;
    private javax.swing.JTable tbAcciones;
    private org.jdesktop.beansbinding.BindingGroup bindingGroup;
    // End of variables declaration//GEN-END:variables

    private MaskFormatter mascara;
    private int pagActual = 0;
    //private int maxResults;
    private int pagTamanno = 200;
    private int numRegistros = 1;
    int pagUltima = 0;

    private org.jdesktop.swingbinding.JTableBinding jTableBinding;
    private List<TableBeanBinding_Accion> listaDatos;    
}
